import request from "../utils/request";

// 注册
export const userRegisterAPI = (registerData) => {
    // 借助于URLSearchParams
    const params = new URLSearchParams();
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post('/user/register', params)
}

// 登录
export const userLoginAPI = (registerData) => {
    // 借助于URLSearchParams
    const params = new URLSearchParams();
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post('/user/login', params)
}

// 获取用户信息
export const getUserInfoAPI = () => {
    return request.get('/user/userInfo')
}

// 更新用户信息
export const updateUserInfoAPI = (params) => {
    return request.put('/user/update', params)
}

// 更新用户头像
export const updateAvatarAPI = (avatarUrl) => {
    // 借助于URLSearchParams
    const params = new URLSearchParams();
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/updateAvatar', params)
}

// 更新用户密码
export const updatePwdAPI = (params) => {
    return request.patch('/user/updatePwd', params)
}